//检查登录 获取缓存
checkLogin();
var worker = getCache('worker');
var ref = GetQueryString('ref') || 0;
if (ref) {
    var sereachData = getCache_outTime('sereach_data', 300) || '';
    if (sereachData) {
        $("#search").val(sereachData.keyword);
        var html = template('search_id', sereachData.data);  //search_id 模板id
        document.getElementById("search_block_id").innerHTML = html;  // search_block_id div id
    }
}

//验证表单并处理登录交互

var ajaxOption = {
    url: worker_search,
    data: {aid: worker.aid, sid: worker.sid, wid: worker.wid, mid: 0},
    success: function (res) {
        setCache_outTime('sereach_data', {keyword: $("#search").val(), data: res});
        var html = template('search_id', res);  //search_id 模板id
        document.getElementById("search_block_id").innerHTML = html;  // search_block_id div id
    },
    error: function (res) {
        if (!res.status) {
            document.getElementById("search_block_id").innerHTML = '';  // search_block_id div id
        }
    }
};
checkform($('#sub_Form'), ajaxOption);

var to_descript = function () {
    $.closeModal('.open-vertical-modal');
    redirect('descript.html');
}

$(document).on('click', '.item-content', function () {
    var index = parseInt(this.getAttribute('data-index'));
    $('.switch_radio').prop('checked', 'false');
    $('#checked_radio' + index).prop('checked', 'checked');
})


//点击下一步弹出弹窗进行选择跳转页面
$(document).on('click', '.open-vertical-modal', function () {
    var mid = $("input[name='switch_radio']:checked").val();
    if (!mid) {
        $.toast("请先确认搜索");
        return
    }
    $.modal({
        title: '<div>请选择操作项目 ' +
            '<a onclick="to_descript()" style="color: red;' +
            ' font-size: 0.6rem;position: absolute; top:0.3rem;right:0.5rem; width:1.5rem;height:1.5rem;' +
            'background-color: #fafafa;border-radius:50%;line-height: 1.5rem;">说明</a></div>',
        verticalButtons: true,
        buttons: [
            {
                text: '代客下单',
                onClick: function () {
                    redirect("create-order.html?mid=" + mid);
                }
            },
            {
                text: '老客户导入',
                onClick: function () {
                    redirect("customer-import.html?mid=" + mid);
                }
            },
            {
                text: '零送水取桶',
                onClick: function () {
                    redirect("take-bucket-detail.html?mid=" + mid);
                }
            },
            {
                text: '水票充值',
                bold: true,
                onClick: function () {
                    redirect("bill-recharge.html?mid=" + mid);
                }
            }
        ]
    })
});

$('#dingdan').click(function (event) {
    redirect('order-list.html');
    // $(this).find('#dingdan_img').attr('src', './image/dingdan-active.png');
    $(this).find('#daoke_img').attr('src', './image/daoke.png');
    $(this).find('#wode_img').attr('src', './image/wode.png');

    return false;
});
$('#daoke').click(function (event) {
    redirect('import.html');
    $(this).find('#dingdan_img').attr('src', './image/dingdan.png');
    // $(this).find('#daoke_img').attr('src', './image/daoke-active.png');
    $(this).find('#wode_img').attr('src', './image/wode.png');
    return false;
});
$('#wode').click(function (event) {
    redirect('center.html');
    $(this).find('#dingdan_img').attr('src', './image/dingdan.png');
    $(this).find('#daoke_img').attr('src', './image/daoke.png');
    // $(this).find('#wode_img').attr('src', './image/wode-active.png');
    return false;
});
